package com.fymxy.question_bank_management.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fymxy.question_bank_management.pojo.Paper;

import java.util.List;

import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;

@Mapper
@Component
public interface PaperMapper {

    int deleteByPrimaryKey(Integer paperNo);

    //添加试卷
    @Insert("insert into paper (paper_no,paper_name,paper_time,paper_type,paper_level,paper_problem_num,paper_test_score,paper_setter_no) values " +
            "(#{paperNo},#{paperName},#{paperTime},#{paperType},#{paperLevel},#{paperProblemNum},#{paperTestScore},#{paperSetterNo})")
    int insert(Paper record);

    int insertSelective(Paper record);

    @Select("select * from paper")
    @Results(id = "PaperMap",value = {
            @Result(column = "paper_no",property = "paperNo"),
            @Result(column = "paper_name",property = "paperName"),
            @Result(column = "paper_time",property = "paperTime"),
            @Result(column = "paper_type",property = "paperType"),
            @Result(column = "paper_level",property = "paperLevel"),
            @Result(column = "paper_problem_num",property = "paperProblemNum"),
            @Result(column = "paper_test_score",property = "paperTestScore"),
            @Result(column = "paper_setter_no",property = "paperSetterNo")
    })
    IPage<Paper> selectAllPaper(Page page);


    @Select("select * from paper where paper_no=#{paperNo} ")
    @Results(id = "PaperMap2",value = {
            @Result(column = "paper_no",property = "paperNo"),
            @Result(column = "paper_name",property = "paperName"),
            @Result(column = "paper_time",property = "paperTime"),
            @Result(column = "paper_type",property = "paperType"),
            @Result(column = "paper_level",property = "paperLevel"),
            @Result(column = "paper_problem_num",property = "paperProblemNum"),
            @Result(column = "paper_test_score",property = "paperTestScore"),
            @Result(column = "paper_setter_no",property = "paperSetterNo")
    })
    Paper selectByPrimaryKey(Integer paperNo);


    int updateByPrimaryKeySelective(Paper record);

    int updateByPrimaryKey(Paper record);


    //查找最大试卷编号(即刚插入的试题)
    @Select("select MAX(paper_no) from paper")
    int getTopPaperNo();


}